﻿@using ControleRepresentante.Logic.Models;
@using WebSite.ViewModels.DetailsViewModels;
@using ControleRepresentante.Common;
@using ControleRepresentante.Logic;

@model UsuarioDetailsViewModel
           
@{ string selectedImagePath = Url.Content("~/Content/permissiongranted.png"); }
@{ string unselectedImagePath = Url.Content("~/Content/permissionnotgranted.png"); }

<table style="border-color:Black; border-width:1px; border-style:solid; border-spacing:0px; border-collapse:collapse;" border="1" cellspacing="0" cellpadding="3">
    <tr style="background-color:Gray; color:White;">
        <td></td>
        @{ Dictionary<Operacao, bool> isOperacaoRelevant = new Dictionary<Operacao, bool>(); }
        @foreach (Operacao operacao in Enum.GetValues(typeof(Operacao)))
        {
            isOperacaoRelevant[operacao] = Model.IsOperacaoRelevant(operacao);
            if (operacao != Operacao.None && isOperacaoRelevant[operacao])
            {
                <td width="60" align="center">@operacao.GetDescription()</td>
            }
        }
    </tr>
    @foreach (Area area in AreaOperacaoRegistry.GetAreas())
    {
        if (Model.IsAreaRelevant(area))
        {
            Permissao permissao = Model.GetPermissao(area);
            Operacao operacoes = permissao == null ? Operacao.None : permissao.Operacao;
            <tr>
                <td style="background-color:Gray; color:White;">@area.GetDescription()</td>
                @{ IEnumerable<Operacao> operacoesInArea = Model.GetOperacoes(area); }
                @foreach (Operacao operacao in Enum.GetValues(typeof (Operacao)))
                {
                    if (operacao != Operacao.None && isOperacaoRelevant[operacao])
                    {
                        <td align="center">
                            @if (operacoesInArea.Contains(operacao))
                            {
                                if ((operacoes & operacao) == operacao)
                                {
                                    <img src="@selectedImagePath"/>
                                }
                                else
                                {
                                    <img src="@unselectedImagePath"/>
                                }
                            }
                        </td>
                    }
                }
            </tr>
        }
    }
</table>
